home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / memory / simpleinit / simpleinit.c next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  1.8 KB  |  57 lines

  1. /*
  2.     File:        SimpleInit.c
  3.  
  4.     Contains:    This snippet demonstrates the writing of a simple init which
  5.                 attempts to allocate a 1 megabyte and then a 2 megabyte handle
  6.                 in the System heap. Please note the 'sysz' resource in the init
  7.                 which is necessary in order to allocate the memory (see Inside 
  8.                 Macintosh Memory page 2-13; NOTE: the 'sysz' resource *is* in 
  9.                 fact still required under System 7 contrary to the statement in 
  10.                 Inside Macintosh Memory)
  11.  
  12.     Written by: Kevin Mellander    
  13.  
  14.     Copyright:    Copyright © 1994-1999 by Apple Computer, Inc., All Rights Reserved.
  15.  
  16.                 You may incorporate this Apple sample source code into your program(s) without
  17.                 restriction. This Apple sample source code has been provided "AS IS" and the
  18.                 responsibility for its operation is yours. You are not permitted to redistribute
  19.                 this Apple sample source code as "Apple sample source code" after having made
  20.                 changes. If you're going to re-distribute the source, we require that you make
  21.                 it clear in the source that the code was descended from Apple sample source
  22.                 code, but that you've made changes.
  23.  
  24.     Change History (most recent first):
  25.                 7/21/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  26.                 
  27.  
  28. */
  29. #include <Memory.h>
  30. #include <Types.h>
  31.  
  32. #pragma segment Main
  33. void main()
  34. {
  35.     Handle    mySysHandle = nil;
  36.     
  37.     mySysHandle = NewHandleSys(1000000);
  38.     
  39.     if (mySysHandle == nil)
  40.         DebugStr("\p the 1,000,000 byte call to mySysHandle failed");
  41.     else
  42.         DebugStr("\p the 1,000,000 byte call to mySysHandle succeeded");
  43.  
  44.     if (mySysHandle)
  45.         DisposeHandle(mySysHandle);
  46.     
  47.     mySysHandle = NewHandleSys(2000000);
  48.     
  49.     if (mySysHandle == nil)
  50.         DebugStr("\p the 2,000,000 byte call to mySysHandle failed");
  51.     else
  52.         DebugStr("\p the 2,000,000 byte call to mySysHandle succeeded");
  53.     
  54.     if (mySysHandle)
  55.         DisposeHandle(mySysHandle);
  56.     
  57. }